﻿#pragma once

#include <QString>

#include <QMap>
#include <SMTData.h>
#include <SMTGUI.h>

namespace aoi 
{
	class Box {
	public:
		int X;
		int Y;
		int height;
		int width;
		float angle = 0;

		Box();
		Box(int X,
			int Y,
			int width,
			int height);
		Box(int X,
			int Y,
			int width,
			int height,
			float angle = 0);
	};

	class Point {
	public:
		int X;
		int Y;

		Point();
		Point(int X,
			int Y);
	};

	class Quad {
	public:
		Point topLeft;
		Point topRight;
		Point bottomLeft;
		Point bottomRight;

		Quad();
		Quad(Point topLeft,
			Point topRight,
			Point bottomLeft,
			Point bottomRight);
	};

	class Ocr {
	public:
		QString ocrText;
		Quad quad;
		float score = 0;

		Ocr();
		Ocr(QString ocrText,
			Quad quad);
	};

	class Classification
	{
	public:
		QString label;
		float score = 0;
		Box clsBox;

		Classification();
		Classification(QString label,
			float score,
			Box clsBox);
	};

	class Segmentation {
	public:
		QString codeType;
		QString mask;
		float score = 0;
		QMap<QString, QString> labelMap;
		Box segBox;

		Segmentation();
		Segmentation(QString codeType,
			QString mask,
			float score,
			QMap<QString, QString> labelMap,
			Box segBox);
	};

	class DetPlusBase {
	public:
		QString label;
		float score = 0;
		Box detBox;

		DetPlusBase();
		DetPlusBase(QString label,
			float score,
			Box detBox);
	};

	class DetPlusDetClassification : public DetPlusBase
	{
	public:
		Classification classification;
		DetPlusDetClassification();
		DetPlusDetClassification(QString label,
			float score,
			Box detBox,
			Classification classification);
	};

	class DetPlusOcr : public DetPlusBase
	{
	public:
		Ocr ocr;

		DetPlusOcr();
		DetPlusOcr(QString label,
			float score,
			Box detBox,
			Ocr ocr);
	};

	class DetPlusSeg : public DetPlusBase
	{
	public:
		Segmentation segmentation;

		DetPlusSeg();
		DetPlusSeg(QString label,
			float score,
			Box detBox,
			Segmentation segmentation);
	};

	class InferenceTime {
	public:
		float all = 0;
		float postAI = 0;
		float stream = 0;

		InferenceTime();
		InferenceTime(float all,
			float postAI,
			float stream);
	};

	class RspStausInfo
	{
	public:
		QString errorCode;
		QString errorMsg;
		bool isSuccess;
		InferenceTime inferenceTime;

		RspStausInfo();
		RspStausInfo(QString errorCode,
			QString errorMsg,
			bool isSuccess,
			InferenceTime inferenceTime);
	};

	enum SceneTag
	{
		DET,
		DET_CLS,
		OCR,
		SEG,
		DET_PLUS_DET,
		DET_PLUS_DET_CLS,
		DET_PLUS_OCR,
		DET_PLUS_SEG,
	};

	class DetPlusRsp
	{
	public:
		QMap<QString, QList<DetPlusDetClassification>> detClsRspMap;
		QMap<QString, QList<DetPlusOcr>> ocrRspMap;
		QMap<QString, QList<DetPlusSeg>> segRspMap;
		RspStausInfo rspStatus;
		QString toString();
	};

	class DetPlusRspParser
	{
	public:
		DetPlusRspParser();
		DetPlusRspParser(SceneTag sceneTag);
		int parseDetPlusOtherRsp(QStringList fileNames, QString rspJson, DetPlusRsp& detPlusRsp);
	private:
		SceneTag sceneTag;
		/*
		* parse DetOcr List from resultArray
		*/
		void parseDetOcrList(QJsonArray& resultArray, QList<DetPlusOcr>& detPlusOcrList, int listLen);
		/*
		* parse DetDetCls List from resultArray
		*/
		void parseDetDetClsList(QJsonArray& resultArray, QList<DetPlusDetClassification>& detPlusDetList, int listLen);
		/*
		* parse DetSeg List from resultArray
		*/
		void parseDetSegList(QJsonArray& resultArray, QList<DetPlusSeg>& detPlusOcrList, int listLen);
	};
}
